package com.xy.order.controller;
import com.ruoyi.common.core.domain.order.dto.ServiceTypeDto;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.xy.order.service.dto.SaleOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/saleOrders")
public class SaleOrdersController extends BaseController {

    @Autowired
    private SaleOrderService saleOrderService;

    /**
     * 获取服务类型列表
     * @param firstMenuId
     * @param upOneLevelId
     * @param secondaryTitleIds
     * @return
     */
    @RequestMapping("/list")
    public Object list(@RequestParam(value = "firstMenuId", required = false) Integer firstMenuId,
                       @RequestParam(value = "upOneLevelId", required = false) Integer upOneLevelId,
                       @RequestParam(value = "secondaryTitleIds", required = false) List<Integer> secondaryTitleIds) {
        // 如果secondaryTitleIds为null，则转换为空列表
        if (secondaryTitleIds == null) {
            secondaryTitleIds = new ArrayList<>();
        }

        // 构建查询参数对象
        ServiceTypeDto queryDto = new ServiceTypeDto();
        queryDto.setFirstMenuId(firstMenuId);
        queryDto.setUpOneLevelId(upOneLevelId);
        queryDto.setSecondaryTitleIds(secondaryTitleIds);

        // 调用服务层方法获取数据
        List<ServiceTypeDto> result = saleOrderService.listAvailableServices(queryDto);

        // 返回统一的结果封装
        return AjaxResult.success(result);
    }
}
